package com.droidnow.adapter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.droidnow.common.ImageLoader;
import com.droidnow.droidaudio.R;
import com.droidnow.model.Rss;

import java.util.ArrayList;
import java.util.HashMap;

public class PlayAdapter extends BaseAdapter {

	private Activity activity;
	private ArrayList<HashMap<String, String>> data;
	private static LayoutInflater inflater = null;
	public ImageLoader imageLoader;
	public Typeface font;

	public PlayAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
		activity = a;
		data = d;
		inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		imageLoader = new ImageLoader(activity.getApplicationContext());
		font = Typeface.createFromAsset(activity.getAssets(), "MyriadPro_Cond.otf");
	}

	public int getCount() {
		return data.size();
	}

	public Object getItem(int position) {
		return position;
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		View vi = convertView;
		if (convertView == null)
			vi = inflater.inflate(R.layout.row_playlist, null);

		TextView title = (TextView) vi.findViewById(R.id.title); // title
		TextView duration = (TextView) vi.findViewById(R.id.duration); // duration
		ImageView playMark = (ImageView) vi.findViewById(R.id.imgPlayMark); // duration
//		ImageView thumb_image = (ImageView) vi.findViewById(R.id.list_image); // thumb image

		title.setTypeface(font);
		duration.setTypeface(font);
		HashMap<String, String> doc;
		doc = data.get(position);

		// Setting all values in list
		title.setText(doc.get(Rss.KEY_TITLE));
		duration.setText(doc.get(Rss.KEY_DURATION));
		if (doc.get(Rss.KEY_STATUS).equals(Rss.KEY_STATUS_SELECTED)) {
			playMark.setVisibility(View.VISIBLE);
			playMark.setImageResource(R.drawable.star_empty);
		} else if (doc.get(Rss.KEY_STATUS).equals(Rss.KEY_STATUS_PLAYING)) {
			playMark.setVisibility(View.VISIBLE);
			playMark.setImageResource(R.drawable.star_full);
		} else{
			playMark.setVisibility(View.INVISIBLE);
		}
		//imageLoader.DisplayImage(doc.get(Rss.KEY_THUMB_URL), thumb_image);
		return vi;
	}
}